[id].vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <LayoutContainer>
  3. <UiLoadingPanel v-if="pending" />
  4. <div v-else>
  5. <h2>Editer la zone de résidence</h2>
  6. <UiForm
  7. ref="form"
  8. :model="ResidenceArea"
  9. :entity="residence_areas"
  10. :submitActions="submitActions"
  11. >
  12. <UiInputText
  13. field="label"
  14. v-model="residence_areas.label"
  15. :rules="rules()"
  16. />
  17. </UiForm>
  18. </div>
  19. <v-btn class="mr-12" @click="quit">
  20. {{ $t('back') }}
  21. </v-btn>
  22. </LayoutContainer>
  23. </template>
  24. <script setup lang="ts">
  25. import { ref } from 'vue'
  26. import { useEntityFetch } from '~/composables/data/useEntityFetch'
  27. import ResidenceArea from '~/models/Billing/ResidenceArea'
  28. import { useRoute } from 'vue-router'
  29. import { useI18n } from 'vue-i18n'
  30. import { AnyJson } from '~/types/data'
  31. import { SUBMIT_TYPE } from '~/types/enum/enums'
  32. const i18n = useI18n()
  33. const { fetch } = useEntityFetch()
  34. const router = useRouter()
  35. const route = useRoute()
  36. const residenceId = ref(parseInt(route.params.id as string))
  37. const goBackRoute = { path: `/parameters`, query: { tab: 'residenceAreas' } }
  38. const submitActions = computed(() => {
  39. let actions: AnyJson = {}
  40. actions[SUBMIT_TYPE.SAVE_AND_BACK] = goBackRoute
  41. return actions
  42. })
  43. const { data: residence_areas, pending } = fetch(
  44. ResidenceArea,
  45. residenceId.value
  46. )
  47. const rules = () => [
  48. (label: string | null) =>
  49. (label !== null && label.length > 0) || i18n.t('please_enter_a_value'),
  50. ]
  51. const quit = () => {
  52. router.push(goBackRoute)
  53. }
  54. </script>